package com.jstyle.jclife.view;

import android.content.Context;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.jstyle.jclife.R;
import com.jstyle.jclife.activity.BreathSettingActivity;
import com.jstyle.jclife.utils.ScreenUtils;
import com.jstyle.jclife.utils.SharedPreferenceUtils;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by Administrator on 2018/9/27.
 */

public class BreathCustomizeDialog extends JstyleDialog {


    @BindView(R.id.bt_title)
    Button btTitle;
    @BindView(R.id.iv_bg)
    ImageView ivBg;
    @BindView(R.id.tv_mins)
    TextView tvMins;
    @BindView(R.id.et_breath_customize)
    EditTextWithDelete etBreathCustomize;
    @BindView(R.id.button_confim)
    Button buttonConfim;
    @BindView(R.id.iv_breath_customize_off)
    ImageView ivBreathCustomizeOff;

    public BreathCustomizeDialog(@NonNull Context context) {
        super(context);

    }

    public BreathCustomizeDialog(@NonNull Context context, int themeResId) {
        super(context, themeResId);
        init(context, themeResId);
    }

    private void init(Context context, int themeResId) {
        initStyle(themeResId);
        initWidth(ScreenUtils.getScreenWidth(context));
        initGravity(Gravity.CENTER);
    }


    @Override
    protected void setContentView() {
        setContentView(R.layout.dialog_breath_customize);
    }


    @OnClick({R.id.iv_breath_customize_off, R.id.button_confim})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_breath_customize_off:
                dismiss();
                break;
            case R.id.button_confim:

                String text=etBreathCustomize.getText().toString();
                if(!TextUtils.isEmpty(text)){
                    int duration=Integer.valueOf(text);
                    if(duration==0){
                        ScreenUtils.showSetSuccessFul(etBreathCustomize,getContext().getString(R.string.time_0));

                    }else{
//                        if(duration>60){
//                            ScreenUtils.showSetSuccessFul(etBreathCustomize,"时间不能超过60");
//                            return;
//                        }
                        SharedPreferenceUtils.setSpInteger(BreathSettingActivity.KEY_DURATION, (int) duration);
                        dismiss();
                    }
                }else {
                    ScreenUtils.showSetSuccessFul(etBreathCustomize,getContext().getString(R.string.Time_empty));
                }

                break;
        }
    }
}
